local S = farming_grain.intllib
local modname=minetest.get_current_modname()

local function farming_grain_register_grain(grain_name_in,grow_steps)
	local grain_name=string.lower(grain_name_in)
	local print_name=string.upper(string.sub(grain_name,1,1))..string.sub(grain_name,2,99)
	local modname=minetest.get_current_modname()
	local farming_name=modname..":"..grain_name -- farming_grain:spelt
	local seed_name=modname..":seed_"..grain_name -- farming_grain:seed_spelt
	local seed_png="farming_grain_"..grain_name.."_seed.png" -- farming_grain_spelt_seed.png

	farming.register_plant(farming_name, {
		description = print_name.." Seed",
		paramtype2 = "meshoptions",
		inventory_image = seed_png,
		steps = grow_steps or 8,
		minlight = 13,
		maxlight = default.LIGHT_MAX,
		fertility = {"grassland"},
		groups = {food_wheat = 1, flammable = 4, seed=1 },
		place_param2 = 3,
	})
	-- roasted 
	minetest.register_craftitem(seed_name.."_roasted", {
		description = S(print_name.." roasted"),
		inventory_image = "farming_grain_seed_roasted.png",
		groups = {food_grain_roasted = 1, flammable = 4},
	})

end


-- registering new grains
farming_grain_register_grain("spelt",7)
farming_grain_register_grain("barley",7)

-- enlarging drop table of grass
farming_grain.enlarge_drop("default:grass_4",{items={modname..":seed_spelt"},rarity=8})
farming_grain.enlarge_drop("default:grass_5",{items={modname..":seed_spelt"},rarity=5})
farming_grain.enlarge_drop("default:grass_4",{items={modname..":seed_barley"},rarity=8})
farming_grain.enlarge_drop("default:grass_5",{items={modname..":seed_barley"},rarity=5})

-- add roasted wheat
minetest.register_craftitem(modname..":seed_wheat_roasted", {
	description = S("Wheat roasted"),
	inventory_image = "farming_grain_seed_roasted.png",
	groups = {food_grain_roasted = 1, flammable = 4},
})

-- add grain powder
minetest.register_craftitem(modname..":grain_powder", {
	description = S("Grain Powder"),
	inventory_image = "farming_grain_roasted_powder.png",
	groups = {food_grain_powder = 1, flammable = 4},
})

-- cold cup of coffee
minetest.register_node(modname..":grain_coffee_cup", {
	description = S("Cup of Grain Coffee"),
	drawtype = "torchlike", --"plantlike",
	inventory_image = "farming_coffee_cup.png",
	wield_image = "farming_coffee_cup.png",
	paramtype = "light",
	walkable = false,
	selection_box = {
		type = "fixed",
		fixed = {-0.25, -0.5, -0.25, 0.25, 0.25, 0.25}
	},
	groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
	on_use = minetest.item_eat(2, "vessels:drinking_glass"),
	sounds = default.node_sound_glass_defaults(),
})

minetest.register_alias("farming:grain_coffee_cup_hot", "farming:grain_coffee_cup")
